﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using Core.BOL;
using Core.DAL;

namespace ScoutNET.Constraints
{
    public class SectionConstraint : IRouteConstraint
    {
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            string key = "lSectionConstraint";
            if (httpContext.Cache[key] == null)
            {
                SectionRepository sr = new SectionRepository();
                httpContext.Cache.Add(key, sr.GetAllSections(), null, DateTime.Now.AddDays(2), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
            }

            return (((List<tSite_Section>)httpContext.Cache[key]).Where(p => p.SystemName.ToLower() == values["systemName"].ToString().ToLower()).Count() > 0);
        }
    } 

}
